package com.hypo.mapper;

import com.hypo.pojo.Emp;
import com.hypo.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    /**
     * 查询所有员工信息
     */
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id limit #{start},#{pageSize}")
    List<Emp> list(EmpQueryParam empQueryParam);

    //基于PageHelper实现分页
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id")
    //List<Emp> list();

    /***
     * 查询总数量
     */
    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id ")
    Long count();

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    @Select("select * from emp where job=1")
    List<Emp> findAll(Emp emp);

    void del(List<Integer> ids);

    Emp getInfo(Integer id);

    void update(Emp emp);

    @MapKey("pos")
    List<Map<String, Object>> countEmpJobData();

    @MapKey("name")
    List<Map> empGenderData();

    @Select("select * from emp where dept_id=#{id}")
    Integer getId(Integer id);

    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp login(Emp emp);
}
